package com.lp.user.control;

import com.lp.common.Result;
import com.lp.common.base.BaseController;
import com.lp.user.dto.Admin;
import com.lp.user.service.AdminService;
import com.lp.user.service.UserService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Api(value ="管理员信息相关的api")
@RequestMapping(value = "/admin")
public class AdminController extends BaseController {

    @Resource(name = "adminService")
    protected AdminService adminService;


    @ApiOperation(value="分页查找管理员信息描述", notes="分页查找管理员信息")
    @ApiImplicitParams({

            @ApiImplicitParam(name = "currrentPage", value = "当前页数", required = true, dataType = "integer",paramType="query" )
    })
    @ApiResponses({
            @ApiResponse(code=200,message = "nextPage：下一个页<br>previousPage:上一页<br>count：总条数<br>pageTotal:总页数<br>end：1没有下一页0.还有下一页<br>dataCount当前页的记录数"),
    })
    @RequestMapping(value = "/page", method = RequestMethod.GET)
    public Result page(Integer currrentPage )throws Exception {

        return adminService.getPage(currrentPage);
    }

    @ApiOperation(value="保存管理员信息", notes="通过参数保存管理员信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "姓名", required = true, dataType = "string",paramType="query" ),
            @ApiImplicitParam(name = "pwd", value = "密码", required = true, dataType = "string",paramType="query" ),
            @ApiImplicitParam(name = "rank", value = "管理员等级", required = true, dataType = "string",paramType="query" )
    })
    @RequestMapping(value = "/saveAdminInfo", method = RequestMethod.POST)
    public Result saveUserInfo(Admin id) {

        Result result=adminService.saveAdminInfor(id);
        return result;
    }

    @ApiOperation(value="修改管理员信息", notes="通过参数修改管理员信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户编号", required = true, dataType = "integer",paramType="query" ),
            @ApiImplicitParam(name = "enabled", value = "是否有效", required = true, dataType = "tinyint",paramType="query",defaultValue="1",allowableValues="1,0",example="1.有效0.无效")
    })
    @RequestMapping(value = "/updateAdminInfo", method = RequestMethod.POST)
    public Result updateUserInfo(Admin id) {
        Result result=adminService.updateAdminInfo(id);
        return result;
    }
}
